#include <ctime>
#include <iostream>

#include "Task.hpp"
#include "ThreadPool.hpp"
using namespace std;

int main() {
  srand(time(nullptr));

  ThreadPool<Task>* tp = ThreadPool<Task>::getInstance(30);

  ThreadPool<Task>* tp1 = ThreadPool<Task>::getInstance();

  ThreadPool<Task>* tp2 = ThreadPool<Task>::getInstance();

  ThreadPool<Task>* tp3 = ThreadPool<Task>::getInstance();

  ThreadPool<Task>* tp4 = ThreadPool<Task>::getInstance();

  tp->Start();  // 运行线程池

  string opers = "+-*/%";

  int len = opers.size();

  while (true) {
    // 1. 构建任务
    int num1 = rand() % 15;

    usleep(10);

    int num2 = rand() % 15;

    char op = opers[rand() % len];

    Task task(num1, num2, op);

    // 2. 将任务发送给线程池使其进行处理
    tp->Push(task);

    printf("The main thread send a task: %d %c %d = ?\n", num1, op, num2);

    sleep(1);
  }
  return 0;
}